<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>cat health API | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'cat-health.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/cat-health.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/cat-health.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/cat-health.html" rel="nofollow" target="_blank">../en/cat-health.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="rest-apis.html">REST APIs</a></span>
»
<span class="breadcrumb-link"><a href="cat.html">cat APIs</a></span>
»
<span class="breadcrumb-node">cat health API</span>
</div>
<div class="navheader">
<span class="prev">
<a href="cat-fielddata.html">« cat fielddata API</a>
</span>
<span class="next">
<a href="cat-indices.html">cat indices API »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="cat-health"></a>cat health API<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/cat/health.asciidoc">edit</a>
</h2>
</div></div></div>

<p>Returns the health status of a cluster, similar to the <a class="xref" href="cluster-health.html" title="Cluster health API">cluster
health</a> API.</p>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="cat-health-api-request"></a>Request<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/cat/health.asciidoc">edit</a>
</h3>
</div></div></div>
<p><code class="literal">GET /_cat/health</code></p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="cat-health-api-desc"></a>Description<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/cat/health.asciidoc">edit</a>
</h3>
</div></div></div>
<p>You can use the cat health API to get the health status of a cluster.</p>
<p><a id="timestamp"></a>This API is often used to check malfunctioning clusters. To help you
track cluster health alongside log files and alerting systems, the API returns
timestamps in two formats:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
<code class="literal">HH:MM:SS</code>, which is human-readable but includes no date information.
</li>
<li class="listitem">
<a href="https://en.wikipedia.org/wiki/Unix_time" class="ulink" target="_top">Unix <code class="literal">epoch</code> time</a>, which is
machine-sortable and includes date information. This is useful for cluster
recoveries that take multiple days.
</li>
</ul>
</div>
<p>You can use the cat health API to verify cluster health across multiple nodes.
See <a class="xref" href="cat-health.html#cat-health-api-example-across-nodes" title="Example across nodes">Example across nodes</a>.</p>
<p>You also can use the API to track the recovery of a large cluster
over a longer period of time. See <a class="xref" href="cat-health.html#cat-health-api-example-large-cluster" title="Example with a large cluster">Example with a large cluster</a>.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="cat-health-api-query-params"></a>Query parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/cat/health.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">format</code>
</span>
</dt>
<dd>
(Optional, string) Short version of the
<a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html" class="ulink" target="_top">HTTP accept header</a>.
Valid values include JSON, YAML, etc.
</dd>
<dt>
<span class="term">
<code class="literal">h</code>
</span>
</dt>
<dd>
(Optional, string) Comma-separated list of column names to display.
</dd>
<dt>
<span class="term">
<code class="literal">help</code>
</span>
</dt>
<dd>
(Optional, boolean) If <code class="literal">true</code>, the response includes help information. Defaults
to <code class="literal">false</code>.
</dd>
<dt>
<span class="term">
<code class="literal">s</code>
</span>
</dt>
<dd>
(Optional, string) Comma-separated list of column names or column aliases used
to sort the response.
</dd>
<dt>
<span class="term">
<code class="literal">time</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>)
Unit used to display time values.
</dd>
<dt>
<span class="term">
<code class="literal">ts</code> (timestamps)
</span>
</dt>
<dd>
(Optional, boolean) If <code class="literal">true</code>, returns <code class="literal">HH:MM:SS</code> and
<a href="https://en.wikipedia.org/wiki/Unix_time" class="ulink" target="_top">Unix <code class="literal">epoch</code></a> timestamps. Defaults to
<code class="literal">true</code>.
</dd>
<dt>
<span class="term">
<code class="literal">v</code>
</span>
</dt>
<dd>
(Optional, boolean) If <code class="literal">true</code>, the response includes column headings.
Defaults to <code class="literal">false</code>.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="cat-health-api-example"></a>Examples<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/cat/health.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="cat-health-api-example-timestamp"></a>Example with a timestamp<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/cat/health.asciidoc">edit</a>
</h4>
</div></div></div>
<p>By default, the cat health API returns <code class="literal">HH:MM:SS</code> and
<a href="https://en.wikipedia.org/wiki/Unix_time" class="ulink" target="_top">Unix <code class="literal">epoch</code></a> timestamps. For example:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /_cat/health?v</pre>
</div>
<div class="console_widget" data-snippet="snippets/1358.console"></div>
<p>The API returns the following response:</p>
<div class="pre_wrapper lang-txt">
<pre class="programlisting prettyprint lang-txt">epoch      timestamp cluster       status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1475871424 16:17:04  elasticsearch green           1         1      1   1    0    0        0             0                  -                100.0%</pre>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="cat-health-api-example-no-timestamp"></a>Example without a timestamp<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/cat/health.asciidoc">edit</a>
</h4>
</div></div></div>
<p>You can use the <code class="literal">ts</code> (timestamps) parameter to disable timestamps. For example:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /_cat/health?v&amp;ts=false</pre>
</div>
<div class="console_widget" data-snippet="snippets/1359.console"></div>
<p>The API returns the following response:</p>
<div class="pre_wrapper lang-txt">
<pre class="programlisting prettyprint lang-txt">cluster       status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
elasticsearch green           1         1      1   1    0    0        0             0                  -                100.0%</pre>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="cat-health-api-example-across-nodes"></a>Example across nodes<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/cat/health.asciidoc">edit</a>
</h4>
</div></div></div>
<p>You can use the cat health API to verify the health of a cluster across nodes.
For example:</p>
<div class="pre_wrapper lang-sh">
<pre class="programlisting prettyprint lang-sh">% pssh -i -h list.of.cluster.hosts curl -s localhost:9200/_cat/health
[1] 20:20:52 [SUCCESS] es3.vm
1384309218 18:20:18 foo green 3 3 3 3 0 0 0 0
[2] 20:20:52 [SUCCESS] es1.vm
1384309218 18:20:18 foo green 3 3 3 3 0 0 0 0
[3] 20:20:52 [SUCCESS] es2.vm
1384309218 18:20:18 foo green 3 3 3 3 0 0 0 0</pre>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="cat-health-api-example-large-cluster"></a>Example with a large cluster<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/cat/health.asciidoc">edit</a>
</h4>
</div></div></div>
<p>You can use the cat health API to track the recovery of a large cluster over a
longer period of time. You can do this by including the cat health API request
in a delayed loop. For example:</p>
<div class="pre_wrapper lang-sh">
<pre class="programlisting prettyprint lang-sh">% while true; do curl localhost:9200/_cat/health; sleep 120; done
1384309446 18:24:06 foo red 3 3 20 20 0 0 1812 0
1384309566 18:26:06 foo yellow 3 3 950 916 0 12 870 0
1384309686 18:28:06 foo yellow 3 3 1328 916 0 12 492 0
1384309806 18:30:06 foo green 3 3 1832 916 4 0 0
^C</pre>
</div>
<p>In this example, the recovery took roughly six minutes, from <code class="literal">18:24:06</code> to
<code class="literal">18:30:06</code>. If this recovery took hours, you could continue to monitor the
number of <code class="literal">UNASSIGNED</code> shards, which should drop. If the number of <code class="literal">UNASSIGNED</code>
shards remains static, it would indicate an issue with the cluster recovery.</p>
</div>

</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="cat-fielddata.html">« cat fielddata API</a>
</span>
<span class="next">
<a href="cat-indices.html">cat indices API »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>